package ar.com.cooker.services.util;

import java.util.Date;

import ar.com.cooker.model.Dificulty;
import ar.com.cooker.model.Ingredient;
import ar.com.cooker.model.IngredientType;
import ar.com.cooker.model.Recipe;
import ar.com.cooker.model.RecipeType;
import ar.com.cooker.model.Region;
import ar.com.cooker.model.UnitType;
import ar.com.cooker.services.pojo.DificultyPojo;
import ar.com.cooker.services.pojo.IngredientPojo;
import ar.com.cooker.services.pojo.IngredientTypePojo;
import ar.com.cooker.services.pojo.RecipePojo;
import ar.com.cooker.services.pojo.RecipeTypePojo;
import ar.com.cooker.services.pojo.RegionOrigenPojo;
import ar.com.cooker.services.pojo.UnitTypePojo;

public class ConvertPojoToBO {

	
	public static Recipe getRecipeToRecipePojo(RecipePojo recipePojo){
		
		Recipe r = new Recipe();
		r.setCreationDate((recipePojo.getCreationDate()==null)?new Date():recipePojo.getCreationDate());
		r.setId(recipePojo.getIdRecipe());
		r.setSummary(recipePojo.getSummary());
		r.setTittle(recipePojo.getTittle());
		r.setDificulty((recipePojo.getDificulty()== null)?null:getDificultyToDificultyPojo(recipePojo.getDificulty()));
		r.setRecipeType((recipePojo.getRecipeType()==null)?null:getRecipeTypeToRecipeTypePojo(recipePojo.getRecipeType()));
		r.setRegion((recipePojo.getCountry()==null)?null:getRegionToRegionOrigen(recipePojo.getCountry()));
		return r;
	}
	
	public static Dificulty getDificultyToDificultyPojo(DificultyPojo dificultyPojo){
		
		Dificulty d = new Dificulty();
		//d.setDescription(dificultyPojo.getDescription());
		d.setId(dificultyPojo.getIdDificulty());
		return d;
	}
	
	public static RecipeType getRecipeTypeToRecipeTypePojo(RecipeTypePojo recipeTypePojo){
		
		RecipeType rt = new RecipeType();
		rt.setDescription(recipeTypePojo.getDescription());
		rt.setId(recipeTypePojo.getIdRecipeType());
		return rt;
	}

	public static Region getRegionToRegionOrigen(RegionOrigenPojo regionOrigenPojo){
		
		Region rg = new Region();
		rg.setContinent(regionOrigenPojo.getRegion());
		rg.setCountry(regionOrigenPojo.getState());
		rg.setRegion(regionOrigenPojo.getZone());
		rg.setId(regionOrigenPojo.getIdCountry());
		return rg;
	}
	
	public static Ingredient getIngredientPojoToIngredient(IngredientPojo ingredientPojo){
		Ingredient i = new Ingredient();
		i.setAmount(Integer.valueOf(ingredientPojo.getAmount()));
		i.setId(ingredientPojo.getIdIngredient());
		i.setName(ingredientPojo.getName());
		i.setPrice(ingredientPojo.getPrice());
		i.setIngredientType((ingredientPojo==null)?null:getIngredientTypeToIngredientTypePojo(ingredientPojo.getIngredientType()));
		i.setUnitType((ingredientPojo.getUnit()==null)?null:getUnitTypeTpUnitTypePojo(ingredientPojo.getUnit()));
		return i;
	}
	
	public static IngredientType getIngredientTypeToIngredientTypePojo(IngredientTypePojo ingredientTypePojo ){
		
		IngredientType it = new IngredientType();
		it.setDescription(ingredientTypePojo.getDescription());
		it.setId(ingredientTypePojo.getIdIngredientType());
		return it;
	}
	
	public static UnitType getUnitTypeTpUnitTypePojo(UnitTypePojo unitTypePojo){
		
		UnitType ut = new UnitType();
		ut.setDescription(unitTypePojo.getName());
		ut.setId(unitTypePojo.getIdUnit());
		return ut;
	}
}
